﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;

namespace ApplicationGenerator.CommonModule
{
    /// <summary>
    /// Klasa pomocnicza do pracy z Wsdl.exe
    /// </summary>
    public class WSDLUtility
    {
        /// <summary>
        /// Ścieżka do pliku Wsdl.exe
        /// </summary>
        private readonly string _wsdlUtilityPath;

        /// <summary>
        /// Konstruktor
        /// </summary>
        public WSDLUtility()
        {
            _wsdlUtilityPath = Path.Combine(Environment.SystemDirectory.Substring(0, 3), @"Program Files\Microsoft SDKs\Windows\v6.0A\Bin\wsdl.exe");
        }

        /// <summary>
        /// Generuje plik klienta dla podanego web serwisu
        /// </summary>
        /// <param name="webServiceUrl">URL do web serwisu</param>
        /// <param name="destinationFile">Ścieżka do docelowego pliku z kodem</param>
        /// <returns>Czy generowanie przebiegło pomyślnie ?</returns>
        public bool GenerateWebServiceClient(string webServiceUrl, string destinationFile)
        {
            Process process = Process.Start(_wsdlUtilityPath, string.Format("/o:\"{0}\" {1}", destinationFile, webServiceUrl));
            process.WaitForExit();
            return process.ExitCode == 0;
        }
    }

}
